package com.rabbit.eap.framework.utils;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @projectName eap
 * @packageName com.rabbit.eap.framework.utils
 * @className HttpServletResponseUtil
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/6/1 18:44
 * <p>Description: HttpServletResponseUtil </p>

 */
public class HttpServletResponseUtil {
    private static String UTF8 = "UTF-8";
    private static String CONTENT_TYPE = "application/json";

    private HttpServletResponseUtil(){
        throw new AssertionError();
    }

    public static void printJson(HttpServletResponse response, Object object) throws Exception{
        response.setCharacterEncoding(UTF8);
        response.setContentType(CONTENT_TYPE);
        PrintWriter printWriter = response.getWriter();
        printWriter.write(JsonUtils.toJSONString(object));
        printWriter.flush();
        printWriter.close();
    }
}
